<!DOCTYPE html>
<html class="x-admin-sm">

<head>
	<meta charset="UTF-8">
	<title>欢迎页面-X-admin2.2</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
	<link rel="stylesheet" href="../X-admin/css/font.css">
	<link rel="stylesheet" href="../X-admin/css/xadmin.css">
	<link rel="stylesheet" type="text/css" href="css/com.css"/>
	<link rel="stylesheet" type="text/css" href="css/myself.css"/>
	<script type="text/javascript" src="../X-admin/lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="../X-admin/js/xadmin.js"></script>
	<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	<title>我的</title>
    <!--<script type="text/javascript">-->
   		<!--document.addEventListener('plusready', function(){-->
   			<!--//console.log("所有plus api都应该在此事件发生后调用，否则会出现plus is undefined。"-->

   		<!--});-->
    <!--</script>-->
    </head>
	<body>
		<header class="m_header">
			<div class="ss_header">
				<div>
				</div>
				<div>
				    <a href="index.html"><img  src="img/8myself_05.gif"/></a>
				</div>
			</div>

			<div class="huahua_header">
				<div class="qian">
					<div class="header_img">

					</div>
					<div>
						<p class="header_name"></p>
						<a title="编辑资料"  onclick="memberdriverid11()"  href="javascript:;">
							<dl >编辑资料</dl>
						</a>
					</div>
				</div>
				<!--<div class="jifen"> -->
					<!--<a href=""><span>签到加20积分></span></a>-->
				<!--</div>-->
			</div>
			
			<div class="gzfsfbhz">
				<div>
					<p class="daiTure"></p>
					<p>待接单</p>
				</div>
				<div>
					<p class="daiTure1"></p>
					<p>待确定</p>
				</div>
				<div>
					<p class="daiTure2"></p>
					<p>进行中</p>
				</div>
				<div>
					<p class="daiTure3"></p>
					<p>评论</p>
				</div>
			</div>
			<div class="m_photo">				
			</div>
		</header>
		<div class="m_collection">
			<div onclick="aTure()">
				<a ><img src="img/8myself_20.gif" /></a>
				<a ><p>待接单</p></a>
			</div>
			<div onclick="bTure()">
				<a ><img src="img/8myself_20.gif" /></a>
				<a ><p>待确定</p></a>
			</div>
			<div onclick="Tureing()">
				<a ><img src="img/8myself_14.gif" /></a>
				<a><p>进行中</p></a>
			</div>
			<div onclick="commentall()">
				<a><img src="img/8myself_16.gif" /></a>
				<a ><p>评论</p></a>
			</div>

		</div>
		<div class="neirong">
			<div class="layui-card" >

			</div>
		</div>
	</body>
<script src="js/jquery.min.js"></script>
<script>
    var user_id=localStorage.getItem("user_id1");
	//待确定
     function aTure(){
         $.ajax({
             type:"POST",
             url: "/Tobeconfirmed",
             data: JSON.stringify({
                 task_user_id:user_id,
                 task_state1:0,
                 task_state:0
             }),
             contentType : "application/json;charset=UTF-8",
             success: function (data) {
                 console.log(data);
                 if(data.status==200){
                     $('.layui-card').html("");
                    var lists=data.data;
                      html1="";
                      html1 += `
                  <div class="layui-card-body ">
                    <table  class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>出发时间</th>
                            <th>起点</th>
                            <th>终点</th>
                            <th>返程时间</th>
                            <th>人数</th>
                            <th>司机状态</th>
                            <th>订单号</th>
                            <th>操作</th>
                        </thead>
                        <tbody class="student-list" id="adminTbody">


                        </tbody>
                    </table>
                </div>

                      `
                     $('.layui-card').append(html1);
                     for (var i = 0; i < lists.length; i++){
                         var html = "";
                         html +=`
                        <tr>
                            <td>${lists[i].task_departure}</td>
                            <td>${lists[i].task_starting}</td>
                            <td>${lists[i].task_end}</td>
                            <td>${lists[i].task_return}</td>
                            <td>${lists[i].task_quantity}</td>
                            <td class="list1" style="color: #00aaee;">${ lists[i].task_state1==0?"司机未接单":"司机接单"}</td>
                            <td>${lists[i].task_order_number}</td>
                            <td class="td-manage">
                                <a title="删除" onclick="memberdel(this,${lists[i].task_id})" href="javascript:;">
                                    <i class="layui-icon">&#xe640;</i>
                                </a>
                            </td>
                        </tr>
                    `
                         $('.student-list').append(html);
                     }

                 }
                 if(data.status==500){
                     alert("查询失败");
                     window.location.reload();
                 }
             }
         });

	}
	//2
    function bTure(){
        $.ajax({
            type:"POST",
            url: "/usertasktrueing",
            data: JSON.stringify({
                task_user_id:user_id,
                task_state1:1,
                task_deposit_state:0,
                task_state:0
            }),
            contentType : "application/json;charset=UTF-8",
            success: function (data) {
                console.log(data);
                if(data.status==200){
                    $('.layui-card').html("");
                    var lists=data.data;
                    html1="";
                    html1 += `
                  <div class="layui-card-body ">
                    <table  class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>出发时间</th>
                            <th>起点</th>
                            <th>终点</th>
                            <th>返程时间</th>
                            <th>人数</th>
                            <th>查看司机</th>
                            <th>价格</th>
                            <th>订单号</th>
                            <th>操作</th>
                        </thead>
                        <tbody class="student-list" id="adminTbody">


                        </tbody>
                    </table>
                </div>

                      `
                    $('.layui-card').append(html1);
                    for (var i = 0; i < lists.length; i++){
                        var html = "";
                        html +=`
                        <tr>
                            <td>${lists[i].task_departure}</td>
                            <td>${lists[i].task_starting}</td>
                            <td>${lists[i].task_end}</td>
                            <td>${lists[i].task_return}</td>
                            <td>${lists[i].task_quantity}</td>
                            <td>
                             <a title="查看司机" onclick="memberdriverid(this,${lists[i].task_driver_id})" href="javascript:;">
                                    <i class="layui-icon">&#xe642;</i>
                              </a>
                            </td>
                            <td style="color: red">${lists[i].task_price}</td>
                            <td>${lists[i].task_order_number}</td>
                            <td class="td-manage">
                                <a title="确定订单" style="width: 10%,color: red;background: #ffff;border-radius: 3px;border: #00F7DE solid 1px" onclick="memberadd(this,${lists[i].task_id},${lists[i].task_order_number},${lists[i].task_price},${lists[i].task_driver_id})" href="javascript:;">
                                    <i class="layui-icon">&#xe642;</i>
                                </a>
                                <a title="删除订单"  style="color: #ccc" onclick="memberdel(this,${lists[i].task_id})" href="javascript:;">
                                    <i class="layui-icon">&#xe640;</i>
                                </a>
                            </td>
                        </tr>
                    `
                        $('.student-list').append(html);
                    }

                }
                if(data.status==500){
                    alert("查询失败");
                    window.location.reload();
                }
            }
        });

    }
    //3
    function Tureing(){
        $.ajax({
            type:"POST",
            url: "/usertasktrueing",
            data: JSON.stringify({
                task_user_id:user_id,
                task_state1:1,
                task_deposit_state:1,
                task_state:0
            }),
            contentType : "application/json;charset=UTF-8",
            success: function (data) {
                console.log(data);
                if(data.status==200){
                    $('.layui-card').html("");
                    var lists=data.data;
                    html1="";
                    html1 += `
                  <div class="layui-card-body ">
                    <table  class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>出发时间</th>
                            <th>起点</th>
                            <th>终点</th>
                            <th>返程时间</th>
                            <th>查看司机位置</th>
                            <th>查看司机信息</th>
                            <th>价格</th>
                            <th>订单号</th>
                            <th>操作</th>
                        </thead>
                        <tbody class="student-list" id="adminTbody">


                        </tbody>
                    </table>
                </div>

                      `
                    $('.layui-card').append(html1);
                    for (var i = 0; i < lists.length; i++){
                        var html = "";
                        html +=`
                        <tr>
                            <td>${lists[i].task_departure}</td>
                            <td>${lists[i].task_starting}</td>
                            <td>${lists[i].task_end}</td>
                            <td>${lists[i].task_return}</td>
                            <td> <a title="查看司机位置" onclick="memberdriverid1(this,${lists[i].task_driver_id})" href="javascript:;">
                                    <i class="layui-icon">&#xe642;</i>
                              </a></td>
                            <td>
                             <a title="查看司机信息" onclick="memberdriverid(this,${lists[i].task_driver_id})" href="javascript:;">
                                    <i class="layui-icon">&#xe642;</i>
                              </a>
                            </td>
                            <td style="color: red">${lists[i].task_price}</td>
                            <td>${lists[i].task_order_number}</td>
                            <td class="td-manage">
                                <a title="退单"  style="color: #ccc" onclick="Tuidan(this,${lists[i].task_id})" href="javascript:;">
                                    <i class="layui-icon">&#xe640;</i>
                                </a>
                            </td>
                        </tr>
                    `
                        $('.student-list').append(html);
                    }

                }
                if(data.status==500){
                    alert("查询失败");
                    window.location.reload();
                }
            }
        });
    }
    //4
    function commentall(){
        alert("我的所有评论"+user_id);
    }

    $(function(){
           //判断下是否登录
            var user_id2=localStorage.getItem("user_id1");
            if (null == user_id2){
                alert("请重新登陆，页面失效");
                window.location.href="login.html";
               }



        //待接受任务
        var user_id1=localStorage.getItem("user_id1");
        $.ajax({
            type:"POST",
            url: "/Tobeconfirmed",
            data: JSON.stringify({
                task_user_id:user_id1,
                task_state1:0,
                task_state:0
            }),
            contentType : "application/json;charset=UTF-8",
            success: function (data) {
                console.log(data);
                if(data.status==200){
                    var  lists = data.data.length;
                    if (0 == lists && "0"==lists ){
                        var html2="";
                        html2 += `<span style="color: #fffffffffff;"> ${lists}</span> `
                        $('.daiTure').append(html2);
                    }else{
                        var html2="";
                        html2 += `<span style="font-weight: 800;color: #ffffffff ;border: red solid 1px; border-radius: 50%;background: #a94442"> ${lists}</span> `
                        $('.daiTure').append(html2);
                    }
                }
                if(data.status==500){
                    alert("查询失败");
                    window.location.reload();
                }
            }
        });
        //待确定任务
        $.ajax({
            type:"POST",
            url: "/usertasktrueing",
            data: JSON.stringify({
                task_user_id:user_id,
                task_deposit_state:0,
                task_state1:1,
                task_state:0
            }),
            contentType : "application/json;charset=UTF-8",
            success: function (data) {
                console.log(data);
                if(data.status==200){
                    var  lists = data.data.length;
                    if (lists==0){
                        var html2="";
                        html2 += `<span style="color: #fffffffffff;"> ${lists}</span> `
                        $('.daiTure1').append(html2);
                    }else{
                        var html2="";
                        html2 += `<span style="font-weight: 800;color: #ffffffff ;border: red solid 1px; border-radius: 50%;background: #a94442"> ${lists}</span> `
                        $('.daiTure1').append(html2);
                    }
                }
                if(data.status==500){
                    alert("查询失败");
                    window.location.reload();
                }
            }
        });
        //进行中的任务
        $.ajax({
            type:"POST",
            url: "/usertasktrueing",
            data: JSON.stringify({
                task_user_id:user_id,
                task_deposit_state:1,
                task_state1:1,
                task_state:0
            }),
            contentType : "application/json;charset=UTF-8",
            success: function (data) {
                console.log(data);
                if(data.status==200){
                    var  lists = data.data.length;
                    if (lists==0){
                        var html2="";
                        html2 += `<span style="color: #fffffffffff;"> ${lists}</span> `
                        $('.daiTure2').append(html2);
                    }else{
                        var html2="";
                        html2 += `<span style="font-weight: 800;color: #ffffffff ;border: red solid 1px; border-radius: 50%;background: #a94442"> ${lists}</span> `
                        $('.daiTure2').append(html2);
					}
                }
                if(data.status==500){
                    alert("查询失败");
                    window.location.reload();
                }
            }
        });
        //用户id评论查看
        $.ajax({
            type:"POST",
            url: "/commentuseridall",
            data: ({
                comment_user_id:user_id,
            }),
            success: function (data) {
                console.log(data);
                if(data.status==200){
                    var  lists = data.data.length;
                    var html2="";
                    html2 += `${lists}`
                    $('.daiTure3').append(html2);
                }
                if(data.status==500){
                    alert("查询失败");
                    window.location.reload();
                }
            }
        });


            //根据id查看用户信息
            $.ajax({
                type:"POST",
                url: "/userIdlist",
                data:({
                    user_id:user_id
                }),
                success: function (data) {
                    console.log(data);
                    if(data.status==200){
                        var  lists = data.data;
                        for (var i = 0; i < lists.length; i++){
                            var html = "";
                            var html1="";
                            html1 +=`
                              ${lists[i].user_name}
                            `
                            if (lists[i].user_personal==null){

                                html +=`
 								<img src="img/8myself_10.gif" />
                                 `

                            }else{

                                html +=`
 								<img style="border-radius: 50%" src="/imgshows?picName=${lists[i].user_personal}"/>
                                 `
							}
                            $('.header_img').append(html);

                            $('.header_name').append(html1);

                        }
                    }
                    if(data.status==500){
                        alert("查询失败");
                        window.location.reload();
                    }
                }
            });


       })

	//确定订单，支付宝支付订单
	function memberadd(obj,id,num,p,did) {
         if (id==null && num==null && p==null && did==null) {
             window.location.href= "myself.html";
             return;
		 }
		 alert(id+"---"+num+"---"+p+"---"+did);
        localStorage.setItem("taskid112",id);
        alert("idid"+localStorage.getItem("taskid112"))
        var uurl ="http://localhost:80/pcpay?out_trade_no="+num;
            uurl +="&total_amount="+p;
		    uurl +="&subject="+id;
		    uurl +="&body="+did;
            window.location.href= uurl;

        // $.ajax({
        //     type:"GET",
        //     url: "/pcpay1",
        //     data: ({
        //         out_trade_no:num,
        //         refund_amount:p,
        //         refund_reason:111
        //     }),
        //     success: function (data1) {
        //         console.log(data1);
        //         if (data1.status==200) {
        //             alert("稍后请查看您的支付宝，退款成功")
        //             $.ajax({
        //                 type:"POST",
        //                 url: "/taskdepositstateTure",
        //                 data: ({
        //                     task_id:id
        //                 }),
        //                 success: function (data2) {
        //                     console.log(data1);
        //                     if (data2.status==200) {
        //                         alert("支付成功")
		// 						window.location.href="/user/myself.html";
        //                         Tureing();
        //                         return
        //                     }
        //                 }
        //             });
        //         }
        //     }
		//
        // });
    }

	   function userupf() {
           var user_id=localStorage.getItem("user_id1");
           if (null == user_id){
               alert("请重新登陆，页面失效");
		   }else {
               window.location.href="userup1.html";
		   }
          return;
       }
   //2查看司机信息  memberdriverid1
    function memberdriverid(obj,id) {
        if (id==null){
            alert("建议删除这一条信息")
            return;
        }
        localStorage.setItem("bus_driver_id1",id);
        xadmin.open('查看司机信息','driveridlist.html',800,600)
        return;
    }
    //查看司机位置，简单的应用百度api
    function memberdriverid1(obj,id) {
        if (id==null){
            alert("建议删除这一条信息")
            return;
        }
        localStorage.setItem("task_driver_id11",id);
        xadmin.open('查看司机信息','driverss.html',800,600)
        return;
    }

    //退单
    function Tuidan(obj,id){
		 alert(id);
        layer.alert("退单须知：在一个小时以内的单免收保障金，超过提一个小时，需要交纳10%的金额，才可退单，您是否还继续退单!", {icon: 2},function () {
            $.ajax({
                type:"POST",
                url: "/Tuidan",
                data: ({
                    task_id:id,
                }),
                success: function (data) {
                    console.log(data);
                    if(data.status==200){
                        var  lists = data.data;
                        var  num = lists.task_order_number;
                        var  pp = lists.task_price;
                           layer.alert("确定退款？", {icon: 6},function () {

								   $.ajax({
									   type:"GET",
									   url: "/refund1",
									   data: ({
										   out_trade_no:num,
										   refund_amount:pp,
										   refund_reason:111
									   }),
									   success: function (data1) {
                                           console.log(data1);
									       if (data1.status==200) {
                                               alert("稍后请查看您的支付宝，退款成功")
												   $.ajax({
													   type:"POST",
													   url: "/Tuidan1",
													   data: ({
                                                           task_id:id
													   }),
													   success: function (data2) {
														   console.log(data1);
														   if (data2.status==200) {
														       alert("您可以发布自己新的任务")
														       window.location.href="/user/index.html"
															   return
														   }
													   }
												   });
										   }
									   }

								   });

                          });
                    }
                    if(data.status==500){
                        layer.alert("退还押金时，自动扣除10%，确定继续退款吗？!", {icon: 2},function () {
								$.ajax({
									type:"GET",
									url: "/refund1",
									data: ({
										out_trade_no:num,
										refund_amount:pp*0.9,
										refund_reason:111
									}),
									success: function (data1) {
										console.log(data1);
										if (data1.status==200) {
											alert("稍后请查看您的支付宝，退款成功")
											$.ajax({
												type:"POST",
												url: "/Tuidan1",
												data: ({
													task_id:id
												}),
												success: function (data2) {
													console.log(data1);
													if (data2.status==200) {
														alert("您可以发布自己新的任务")
														window.location.href="/user/index.html"
														return
													}
												}
											});
										}
									}

								});

						});
                    }
                }
            });

        });
	}


    //编辑个人信息
    function memberdriverid11() {
        xadmin.open('修改个人信息','userup1.html',800,600)
        return;
    }

    /*用户-删除*/
    function memberdel(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            //发异步删除数据
            console.log(id);
            $.ajax({
                type:"POST",
                url: "/deletetask",
                data:({
                    task_id:id
                }),
                success: function (data) {
                    console.log(data);
                    if(data.status==401){
                        alert("熔断开启，系统异常");
                        window.location.href="./login.html";
                        return;
                    }
                    if(data.status==200){
                        window.location.reload();
                        $(".layui-form-checked").not('.header').parents('tr').remove();
                    }
                    if(data.status==500){
                        alert("删除S");
                        window.location.reload();
                        $(".layui-form-checked").not('.header').parents('tr').remove();
                    }
                }
            })
            $(obj).parents("tr").remove();
            layer.msg('已删除!',{icon:1,time:1000});
        });
    }



</script>
</html>
